package cn.yh.province.dao.Impl;

import cn.yh.province.dao.ProvinceDao;
import cn.yh.province.pojo.Province;
import cn.yh.province.utils.JDBCUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class ProvinceDaoImpl implements ProvinceDao {
    //使用jdbcTemplate操作数据库

    private final JdbcTemplate jdbcTemplate = new JdbcTemplate(JDBCUtils.getDataSource());

    @Override
    public List<Province> getAllProvince() {

        String sql = "select * from province";
        List<Province> provinceList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(Province.class));
        return provinceList;
    }
}
